﻿using System;
using System.Net;

namespace SCG.SolarVengeanceEngine.StarShips
{
    //EMines
    public class EMine : StarShip
    {
        //constructor
        public EMine(SVGame game, Player owner, StarSystem origin)
            : base(game, owner, 1, 0, origin)
        {
        }

        //Starship type name
        public override string Name
        {
            get
            {
                return "EMine";
            }
        }

        //description
        public override string Description
        {
            get
            {
                return "E-Mines detonate whenever an enemy StarShip is adjacent.  Both the E-Mine and the target is destroyed in the blast.  MineSweeper StarShips can absorb E-Mine detonations with their Armor.";
            }
        }

        //Starship type
        public override StarShipType ShipType
        {
            get
            {
                return StarShipType.EMine;
            }
        }

        //Can target a StarShip
        public override bool CanExecuteOrder(OrderType ot)
        {
            switch (ot)
            {
                case OrderType.Defend:
                case OrderType.DefendPoint:
                case OrderType.TargetStarShip:
                    return true;
                default:
                    return base.CanExecuteOrder(ot);
            }
        }

        //can it target a specific StarShip?
        public override bool CanTargetStarShip(StarShip ship, bool respectAlliance)
        {
            if (respectAlliance)
                return !Owner.FriendlyTo(ship.Owner);
            else
                return !ship.OwnedByCurrentPlayer;
        }

        //Can destroy anything
        public override bool CanDestroy(StarShip target)
        {
            return true;
        }

        //Detonate EMines!
        protected internal override void PreMoveProcessing()
        {
            StarShip emineTarget = Game.AdjacentEnemyStarShip(this, X, Y, false, true);
            if (emineTarget != null)
            {
                if (emineTarget.ShipType == StarShipType.MineSweeper)
                    emineTarget.Damage(1, false);
                else
                    Game.DestroyStarShip(emineTarget);
                Game.DestroyStarShip(this);
            }
        }
    }
}
